package cm.dpassyann.speedDating.ui.activity.update.task;

import java.io.File;




/**
 * Bean permettant à {@link UpdateApplicationTask} de transmettre un résultat
 * entre {@link UpdateApplicationTask#doInBackground(Integer...)} et
 * {@link UpdateApplicationTask#onPostExecute(UpdateTaskResult)}
 * 
 * @author dpassyann
 */
public class UpdateTaskResult {

    private final Exception exception;

    private final boolean   upToDate;

    private final File      downloadedFile;

    private UpdateTaskResult(Exception exception, boolean upToDate, File downloadedFile) {
        this.exception = exception;
        this.upToDate = upToDate;
        this.downloadedFile = downloadedFile;
    }

    public Exception getException() {
        return exception;
    }

    public boolean isUpToDate() {
        return upToDate;
    }

    public File getDownloadedFile() {
        return downloadedFile;
    }

    /**
     * Factory method
     */
    public static UpdateTaskResult exception(Exception e) {
        return new UpdateTaskResult(e, false, null);
    }

    /**
     * Factory method
     */
    public static UpdateTaskResult upToDate() {
        return new UpdateTaskResult(null, true, null);
    }

    /**
     * Factory method
     */
    public static UpdateTaskResult updateAvailable(File downloadedFile) {
        return new UpdateTaskResult(null, false, downloadedFile);
    }

}
